
<?php


if (!empty($_SESSION['login'])&&!empty($_SESSION['email'])){
    $db = new Mypdo();
if(empty($_POST)){

?>

<h1>Crée proprietaire</h1>

<form method="post" action="#">

	    <p>
            <h3>Identité</h3>
            <label for="genre_propri">Genre :</label><select name="genre_propri" id="genre_propri" required="required">
                <option></option>
                <option value="M">M.</option>
                <option value="Mme">Mme.</option>
                <option value="Mlle">Mlle.</option>
            </select>
	        <label for="nom_propri">Nom:</label><input name="nom_propri" type="text" id="nom_propri" required="required" pattern="[a-zA-Zàâäéèêëùûüîïôöÿ\\-]*" />
	        <label for="prenom_propri">Prenom :</label><input type="text" name="prenom_propri" id="prenom_propri" required="required" pattern="[a-zA-Zàâäéèêëùûüîïôöÿ\\-]*" /><br />
            <label for="siret_propri">Siret :</label><input type="text" name="siret_propri" id="siret_propri" pattern="[0-9]{14}"  />
            <label for="ape_propri">Ape :</label><input type="text" name="ape_propri" id="ape_propri" pattern="[0-9]{4}[A-Z]" /><br />
	    </p>
        <p>
            <?php include_once('Form_adresse.inc.php'); ?>
        </p>
        <p>
            <h3>Contact</h3>
            <label for="num_fix_propri">Numero fix</label><input name="num_fix_propri" type="text" id="num_fix_propri" required="required" pattern="0[0-589]((\\.[0-9]{2}){4}|(\\-[0-9]{2}){4}|[0-9]{8})" />
            <label for="num_port_propri">Numero portable :</label><input type="text" name="num_port_propri" id="num_port_propri" pattern="0[6-7]((\\.[0-9]{2}){4}|(\\-[0-9]{2}){4}|[0-9]{8})" /><br />
            <label for="email_propri">Email :</label><input type="text" name="email_propri" id="email_propri" pattern="^[a-z0-9._%+-]+@[a-z0-9.-]+\.[a-z]{2,4}$"  />
        </p>


	    <p><input type="reset" value="Annuler" /><input type="submit" value="Valider" /></p>
</form>

<?php }else{
    $propri = new Proprietaire($_POST);
    $propri->setAdressePropri(new Adresse($_POST));
    var_dump($propri);

    $propriManager = new ProprietaireManager($db);
    $id = $propriManager->add($propri);

    header('Location: index.php?page=111&id='.$id);

}
}else{
    header('Location: index.php');
}